package com.china.school.aware;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.apache.tomcat.util.json.JSONParser;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.context.ServletConfigAware;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

public class AwareTest implements ServletContextAware, BeanNameAware , BeanFactoryAware, ApplicationContextAware,
        BeanClassLoaderAware , ServletConfigAware, EnvironmentAware, ResourceLoaderAware
{

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("AwareTest.xml");
        AwareTest awareTest =(AwareTest) ctx.getBean("awareTest");
        System.out.println(awareTest);

    }
//DefaultBeanDefinitionDocumentReader 91
    //NamespaceHandlersupport
    //BeanDefinitionParser


    private ServletContext servletContext;
    private ServletConfig servletConfig;
    private BeanFactory beanFactory;
    private ApplicationContext applicationContext;
    private Environment environment;
    private ClassLoader classLoader;
    private ResourceLoader resourceLoader;
    private String beanName;
     @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
         this.classLoader = classLoader;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void setEnvironment(Environment environment) {
//        this.environment = environment;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @Override
    public void setServletConfig(ServletConfig servletConfig) {
        this.servletConfig = servletConfig;
    }


    @Override
    public void setBeanName(String s) {
        this.beanName = s;
    }
    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;

    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("AwareTest{");
        sb.append("servletContext=").append(servletContext);
        sb.append(", servletConfig=").append(servletConfig);
        sb.append(", beanFactory=").append(beanFactory);
        sb.append(", applicationContext=").append(applicationContext);
        sb.append(", environment=").append(environment);
        sb.append(", classLoader=").append(classLoader);
        sb.append(", resourceLoader=").append(resourceLoader);
        sb.append(", beanName='").append(beanName).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
